﻿using System;
using System.Web.Mvc;
using iss.sg4210.se18.team6s.jass.DAL;
using iss.sg4210.se18.team6s.jass.DAL.DataAccess.Interfaces;

namespace iss.sg4210.se18.team6s.Controllers
{
    [Authorize()]
    public class GeoAreaController : Controller
    {
        //
        // GET: /GeoArea/

        public ActionResult Index()
        {
            return View(DataAccessFactory.Instance.GeographicalArea.FindAllGeographicalAreas());
        }

        //
        // GET: /GeoArea/Details/5

        public ActionResult Details(int id)
        {
            GeoArea g = DataAccessFactory.Instance.GeographicalArea.GetGeographicalArea(id);
            return View(g);
        }

        //
        // GET: /GeoArea/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /GeoArea/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here
                GeoArea g = new GeoArea();
                UpdateModel(g, collection);
                DataAccessFactory.Instance.GeographicalArea.AddGeographicalArea(g);
                return RedirectToAction("Index");
            }
            catch (Exception ex)
            {
                return View();
            }
        }

        //
        // GET: /GeoArea/Edit/5

        public ActionResult Edit(int id)
        {
            GeoArea GeoArea = DataAccessFactory.Instance.GeographicalArea.GetGeographicalArea(id);
            return View(GeoArea);
        }

        //
        // POST: /GeoArea/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here

                GeoArea g = DataAccessFactory.Instance.GeographicalArea.GetGeographicalArea(id);
                UpdateModel(g);
                DataAccessFactory.Instance.GeographicalArea.UpdateGeographicalArea(g);
                return RedirectToAction("Details", g);
            }
            catch (Exception ex)
            {
                return View();
            }
        }

        //
        // GET: /GeoArea/Delete/5

        public ActionResult Delete(int id)
        {
            GeoArea g = DataAccessFactory.Instance.GeographicalArea.GetGeographicalArea(id);
            return View(g);
        }

        //
        // POST: /GeoArea/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
                DataAccessFactory.Instance.GeographicalArea.DeleteGeographicalArea(id);
                return RedirectToAction("Index");
            }
            catch (Exception ex)
            {
                return View();
            }
        }
    }
}
